#define _CRT_SECURE_NO_WARNINGS 1
#include <queue>
class Comp
{
public:
    bool operator()(int a, int b)
    {
        return a > b;
    }
};

void mysort(vector<vector<int>>& arr, int left, int right)
{
    if (left >= right) return;
    int begin = left, end = right, key = arr[left][0];
    for (int i = left; i <= right;)
    {
        if (arr[i][0] > key) swap(arr[i], arr[right--]);
        else if (arr[i][0] < key) swap(arr[i++], arr[left++]);
        else i++;
    }
    mysort(arr, begin, left - 1);
    mysort(arr, right + 1, end);
}
class Solution {
public:
    int minmumNumberOfHost(int n, vector<vector<int> >& startEnd) {
        mysort(startEnd, 0, n - 1);
        priority_queue<int, vector<int>, Comp> per;
        per.push(startEnd[0][1]);
        for (int i = 1; i < n; i++)
        {
            int tmp = per.top();
            if (startEnd[i][0] >= tmp)
            {
                per.pop();
                per.push(startEnd[i][1]);
            }
            else
            {
                per.push(startEnd[i][1]);
            }
        }

        return per.size();
    }
};